package jdk.lambda.collectors;

import jdk.entity.UserEntity;
import jdk.lambda.collectors.extend.CharSequenceBO;
import jdk.util.ChineseNameUtil;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * joining 案例
 * @author songyafei
 */
public class JoiningTest {

    public static void main(String[] args) {
        List<UserEntity> L = new ArrayList<UserEntity>();
        L.add(new UserEntity(1L, 17, ChineseNameUtil.getName(), LocalDate.now().minusYears(1),Double.valueOf(2000)));
        L.add(new UserEntity(2L, 12, ChineseNameUtil.getName(), LocalDate.now().minusYears(2),Double.valueOf(3000)));
        L.add(new UserEntity(3L, 14, ChineseNameUtil.getName(), LocalDate.now().minusYears(3),Double.valueOf(4000)));
        L.add(new UserEntity(4L, 27, ChineseNameUtil.getName(), LocalDate.now().minusYears(1),Double.valueOf(1000)));
        L.add(new UserEntity(5L, 24, ChineseNameUtil.getName(), LocalDate.now(),Double.valueOf(10000)));
        String c1 = L.stream().filter(m -> m.getAge() < 20).map(m-> m.getName() + " - ").collect(Collectors.joining());
        String c2 = L.stream().filter(m -> m.getAge() < 20).map(m-> m.getName() + " - ").collect(Collectors.joining(new CharSequenceBO()));
        String c3 = L.stream().filter(m -> m.getAge() < 20).map(m-> m.getName() + " - ").collect(Collectors.joining(",","[","]"));
        System.out.println(c1);
        System.out.println(c2);
        System.out.println(c3);

    }
}
